/*******************************************************************
����:buzzer.h
����:������ģ��ͷ�ļ�
����:Ҧ��ƽ
����:2010-01-04
*******************************************************************/
/*******************************************************************
   ע������ 
*******************************************************************/ 
/*
  ���ļ�Ϊ����ӿ��ļ�����ݲ�ͬ��Ŀ�Ͳ�ͬƽ̨��Ҫ���ʵ��Ķ���������ô���Ķ�����Ŀ�͵�Ƭ��ƽ̨������
*/
/*******************************************************************
                               ��ֹ�ظ���������ظ�������?���� 
*******************************************************************/ 
#ifndef     __BUZZER_H__
    #define __BUZZER_H__
/*******************************************************************
                              ��ģ��Ҫ���õ�����ģ��ͷ�ļ�
*******************************************************************/
#include "sc95f.h"
#include "../FWLib/SC95F_Lib/inc/sc95f_pwm.h"
#include "SC_Init.h"	// MCU initialization header file, including all firmware library header files
#include "SC_it.h"
#include "..\Drivers\SCDriver_list.h"
#include "HeadFiles\SysFunVarDefine.h"
#include <SC95F8x7x_C.H>
/*******************************************************************
                                   ��ģ��EXTERN�궨����
*******************************************************************/
    #ifdef      EXTERN
        #undef  EXTERN
    #endif

    #ifdef  __BUZZER_C__
        #define EXTERN
    #else
        #define EXTERN  extern
    #endif

typedef enum {
	BUZZER_ON,
	BUZZER_OFF,
	BUZZER_STAT_OFF,
	BUZZER_ERR
}BUZZER_STAT;
extern BUZZER_STAT buzzer_stat;

/*******************************************************************
                                          ����������
*******************************************************************/
#define OFF                                  (0)
#define ON                                   (1)
#define TRUE                                 (1)
#define PRJ_OPTION_BUZZER                    (ON)
#define BUZZER_INTERFACE_IS_MACRO            ( TRUE )
#define BUZZER_NEED_ECHO                     ( OFF )       /* �������Ƿ���Ҫ������Ҫ:ON ,��Ҫ:OFF */
/*******************************************************************
                                         �������˿���
*******************************************************************/
#define P_BUZZER                             ( (3<<3) + 1 )
#define PB_BUZZER_DIR                        ( 0 )
//#define P_BUZZER_DATA                        ( P1 )
#define PB_BUZZER_EN                         P01
#define PB_BUZZER_DATA                       ( 0 )

#if ( defined( BUZZER_NEED_ECHO ) && ( BUZZER_NEED_ECHO == ON ) )
    #define P_BUZZER_ECHO_DIR                ( P1 )
    #define PB_BUZZER_ECHO_DIR               ( 1 )
    #define P_BUZZER_ECHO_DATA               ( P1 )
    #define PB_BUZZER_ECHO_DATA              ( 1 )
#endif
/*******************************************************************
                          ���������� 
*******************************************************************/
#define SOUND                                ( 1 )

#if ( defined( BUZZER_NEED_ECHO ) && ( BUZZER_NEED_ECHO == ON ) )
    #define C_BUZZER_ECHO_TIME               ( 1 * SECOND )
#endif
/*******************************************************************
                                         ����������
*******************************************************************/
typedef struct _STRUCT_BUZZER{
                   uint8_t  u8BuzzerSoundCount;
			       uint8_t  u8BuzzerOnTime;
			       uint8_t  u8BuzzerOffTime;
                   uint8_t  output;              /* 1: 蜂鸣器动作 */
                             }STRUCT_BUZZER;
EXTERN STRUCT_BUZZER  sgBuzzer;


typedef struct {
    uint8_t   OnTime;
    uint8_t   OffTime;
    uint16_t   PwmCount;
    uint8_t   Output;

    uint8_t   Timer;
}pwmGen_t;

/*******************************************************************
                                        �꺯��������
*******************************************************************/
/*=======================================================================
������BUZZER_SOUND_TYPE_SECOND_UNIT
���ܣ���������������(����ʱ����������?��λ,���ε������������?255��,�����ʱ��Ϊ255��ϵͳʱ�ӽ���)
���룺BZ_CNT������������?���еĴ���
      BZ_ON_TIME����������������еĿ�ʱ��?
      BZ_OFF_TIME����������������е�ֹͣʱ��?
�������?
��д��Ҧ��ƽ
���ڣ�2010-01-04
=======================================================================*/
#if ( defined( BUZZER_INTERFACE_IS_MACRO ) && ( BUZZER_INTERFACE_IS_MACRO == TRUE ) )

    #define BUZZER_SOUND_TYPE_SECOND_UNIT( BZ_CNT, BZ_ON_TIME, BZ_OFF_TIME )  do{                  \
	        sgBuzzer.u8BuzzerSoundCount = BZ_CNT;                                              \
	        sgBuzzer.u8BuzzerOnTime = BZ_ON_TIME;                                              \
	        sgBuzzer.u8BuzzerOffTime = BZ_OFF_TIME;                                            \
                                                                                }while( 0 )
#else
    #define BUZZER_SOUND_TYPE_SECOND_UNIT( BZ_CNT, BZ_ON_TIME, BZ_OFF_TIME )

#endif
/*=======================================================================
������BUZZER_SOUND_TYPE_MS_UNIT
���ܣ���������������(����ʱ������Ժ����?��λ,���ε����������?255��,�����ʱ��Ϊ255��ϵͳʱ�ӽ���)
���룺BZ_CNT������������?���еĴ���
      BZ_ON_TIME����������������еĿ�ʱ��?
      BZ_OFF_TIME����������������е�ֹͣʱ��?
�������?
��д��Ҧ��ƽ
���ڣ�2010-01-04
=======================================================================*/
#define BUZZER_SOUND_TYPE_MS_UNIT( BZ_CNT, BZ_ON_TIME, BZ_OFF_TIME )  do{                          \
	    sgBuzzer.u8BuzzerSoundCount = BZ_CNT;                                                  \
	    sgBuzzer.u8BuzzerOnTime = BZ_ON_TIME / C_SYSTEM_TIME_TICK;                             \
	    sgBuzzer.u8BuzzerOffTime = BZ_OFF_TIME / C_SYSTEM_TIME_TICK;                           \
                                                                        }while( 0 )  
/*=======================================================================
������STOP_BUZZER
���ܣ�
���룺
�������?
��д��Ҧ��ƽ
���ڣ�2010-01-04
=======================================================================*/
#define STOP_BUZZER( )  do{                                                                        \
	    sgBuzzer.u8BuzzerSoundCount = 0;                                                       \
	    sgBuzzer.u8BuzzerOnTime = 0;                                                           \
	    sgBuzzer.u8BuzzerOffTime = 0;                                                          \
                          }while( 0 )                                                                        
/*=======================================================================
������OPEN_BUZZER_ECHO
���ܣ�������������
���룺��
�������?
��д��Ҧ��ƽ
���ڣ�2010-01-04
=======================================================================*/
#if ( defined( BUZZER_NEED_ECHO ) && ( BUZZER_NEED_ECHO == ON ) )
   
    #define OPEN_BUZZER_ECHO()  do{                                                                \
    	        SetGpioDirection( P_BUZZER_ECHO_DIR, P_BUZZER_ECHO_DATA,BP_BUZZER_ECHO_DATA );\
    	        u8lBuzzerEchoTime = C_BUZZER_ECHO_TIME;                                            \    	        
                                  }while( 0 )
#endif
/*=======================================================================
 ������TURN_ON_BUZZER
 ���ܣ��򿪷����� 
 ���룺��  
 �������? 
 ��д��Ҧ��ƽ 
 ���ڣ�2010-01-04
=======================================================================*/
    #define TURN_ON_BUZZER()  do{                                                                  \
    	        PB_BUZZER_EN=ON;                                                                   \
    /*PWM0����PWM_CmdEX(PWM0_Type,ENABLE);  */                                                      \          
                                }while( 0 )
/*=======================================================================
 ������CLOSE_BUZZER_ECHO
 ���ܣ��ط��������� 
 ���룺�� 
 �������? 
 ��д��Ҧ��ƽ 
 ���ڣ�2010-01-10
=======================================================================*/
#if ( defined( BUZZER_NEED_ECHO ) && ( BUZZER_NEED_ECHO == ON ) )
   
    #define CLOSE_BUZZER_ECHO()  do{                                                               \
    	        CLR_GPIO_BIT_WITHOUT_DIR( P_BUZZER_ECHO_DATA,PB_BUZZER_ECHO_DATA );                \ 
    	                           }while( 0 )
#endif
/*=======================================================================
������TURN_OFF_BUZZER
���ܣ��ط���������
���룺��
�������?
��д��Ҧ��ƽ
���ڣ�2010-01-04
=======================================================================*/
    #define TURN_OFF_BUZZER()  do{                                                                 \
    	            PB_BUZZER_EN=OFF;                  \
        /*PWM0����PWM_CmdEX(PWM0_Type,DISABLE);*/       \
                                 }while( 0 )
/*******************************************************************
                                        ����ӿں���������?
*******************************************************************/
void BuzzerTask( void );
void Buzzerinit(void);
void Buzzer_key(void);
void Buzzer_open(void);
void Buzzer_close(void);
void Buzzer_err(void);
void Buzzer_Bathtube(void);
void Buzzer_clear(void);
void Buzzer_clear_err_in_poweroff(void);
/*********************************************************/
#endif /* __BUZZER_H__ */
/*******************************************************************
                                          END OF FILE
*******************************************************************/


